<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="项目名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预算金额" prop="ysMoney">
        <el-input
          v-model="queryParams.ysMoney"
          placeholder="请输入预算金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实施部门" prop="deployDept">
        <el-input
          v-model="queryParams.deployDept"
          placeholder="请输入实施部门"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['hsj:project:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['hsj:project:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['hsj:project:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['hsj:project:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="项目名称" align="center" prop="name" />
      <el-table-column label="预算金额" align="center" prop="ysMoney" />
      <el-table-column label="金额范围" align="center" prop="rangeMoney" />
      <el-table-column label="实施部门" align="center" prop="deployDept" />
      
      <el-table-column label="第一步" align="center">
      <el-table-column label="预算会审" align="center" prop="stepYshs" /></el-table-column>

      <el-table-column label="第二步" align="center">
      <el-table-column label="选队" align="center" prop="stepXd" /></el-table-column>

      <el-table-column label="第三步" align="center">
      <el-table-column label="费用会审" align="center" prop="stepFyhs" /></el-table-column>
      
      <el-table-column label="第四步" align="center">
      <el-table-column label="第四步：合同会审" align="center" prop="stepHths" /></el-table-column>

      <el-table-column label="第五步" align="center">
      <el-table-column label="合同签署" align="center" prop="stepHtqs" /></el-table-column>

      <el-table-column label="第六步" align="center">
      <el-table-column label="验收" align="center" prop="stepYs" /></el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-info"
            @click="displayDetail(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['hsj:project:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['hsj:project:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改项目实施流程对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="name">
              <el-input v-model="form.name" placeholder="请输入项目名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实施部门" prop="deployDept">
              <el-input v-model="form.deployDept" placeholder="请输入实施部门" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="最小金额" prop="minMoney">
              <el-input v-model="form.minMoney" placeholder="请输入最小金额" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="最大金额" prop="maxMoney">
              <el-input v-model="form.maxMoney" placeholder="请输入最大金额" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="预算金额" prop="ysMoney">
          <el-input v-model="form.ysMoney" placeholder="请输入预算金额" />
        </el-form-item>

        <el-form-item label="第一步：预算会审" prop="stepYshs">
          <el-input v-model="form.stepYshs" placeholder="请输入第一步：预算会审" />
        </el-form-item>
        <el-form-item label="第二步：选队" prop="stepXd">
          <el-input v-model="form.stepXd" placeholder="请输入第二步：选队" />
        </el-form-item>
        <el-form-item label="第三步：费用会审" prop="stepFyhs">
          <el-input v-model="form.stepFyhs" placeholder="请输入第三步：费用会审" />
        </el-form-item>
        <el-form-item label="第四步：合同会审" prop="stepHths">
          <el-input v-model="form.stepHths" placeholder="请输入第四步：合同会审" />
        </el-form-item>
        <el-form-item label="第五步：合同签署" prop="stepHtqs">
          <el-input v-model="form.stepHtqs" placeholder="请输入第五步：合同签署" />
        </el-form-item>
        <el-form-item label="第六步：验收" prop="stepYs">
          <el-input v-model="form.stepYs" placeholder="请输入第六步：验收" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog v-if="currentDetailData" title="详情" :visible.sync="detailVisible" width="1200px" append-to-body>
      <el-card header="基础信息" style="margin-bottom: 20px">
        <ul class="detail-wrap">
          <li class="detail-item">
            <div class="label">项目名称</div>
            <div class="value">{{ this.currentDetailData.name }}</div>
          </li>
          <li class="detail-item">
            <div class="label">实施部门</div>
            <div class="value">{{ this.currentDetailData.deployDept }}</div>
          </li>
          <li class="detail-item">
            <div class="label">预算金额</div>
            <div class="value">{{ this.currentDetailData.ysMoney }}</div>
          </li>
          <li class="detail-item">
            <div class="label">金额范围</div>
            <div class="value">{{ this.currentDetailData.rangeMoney }}</div>
          </li>  
        </ul>
      </el-card>
      <el-card header="实施流程">
        <el-steps :active="stepActive" finish-status="success" align-center>
          <el-step title="第一步：预算会审" :description="currentDetailData.stepYshs"></el-step>
          <el-step title="第二步：选队" :description="currentDetailData.stepXd"></el-step>
          <el-step title="第三步：费用会审" :description="currentDetailData.stepFyhs"></el-step>
          <el-step title="第四步：合同会审" :description="currentDetailData.stepHths"></el-step>
          <el-step title="第五步：合同签署" :description="currentDetailData.stepHtqs"></el-step>
          <el-step title="第六步：验收" :description="currentDetailData.stepYs"></el-step>
        </el-steps>
        <div class="tools">
          <el-button type="primary" @click="next">下一步</el-button>
        </div>
      </el-card>
    </el-dialog>
  </div>
</template>

<script>
import { listProject, getProject, delProject, addProject, updateProject } from "@/api/hsj/project";

export default {
  name: "Project",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 项目实施流程表格数据
      projectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        ysMoney: null,
        minMoney: null,
        maxMoney: null,
        deployDept: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      detailVisible: false,
      currentDetailData: null,
      stepActive: 0
    };
  },
  created() {
    this.getList();
  },
  methods: {
    displayDetail(row){
      getProject(row.id).then(response => {
        this.stepActive = 0;
        this.detailVisible = true
        this.currentDetailData = response.data
      })
    },
    next() {
      if (this.stepActive++ > 5) this.stepActive = 0;
    },
    /** 查询项目实施流程列表 */
    getList() {
      this.loading = true;
      listProject(this.queryParams).then(response => {
        this.projectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        name: null,
        ysMoney: null,
        minMoney: null,
        maxMoney: null,
        deployDept: null,
        stepYshs: null,
        stepXd: null,
        stepFyhs: null,
        stepHths: null,
        stepHtqs: null,
        stepYs: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目实施流程";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProject(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改项目实施流程";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateProject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除项目实施流程编号为"' + ids + '"的数据项？').then(function() {
        return delProject(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('hsj/project/export', {
        ...this.queryParams
      }, `project_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style lang="scss" scoped>
.detail-wrap{
  list-style: none;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  padding: 0 0 0 10px;

  .detail-item{
    width: calc(50% - 10px);
    padding: 5px;
    border: 1px solid #dedede;
    margin-right: 10px;
    margin-bottom: 10px;
    .label{
      color: #666666;
      margin-bottom: 5px;
    }
  }
}

.tools{
  width: 90px;
  margin: 12px auto;
}
</style>
